package com.pureut.storage.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.security.utils.DictUtils;
import com.pureut.storage.domain.PickingReturns;
import com.pureut.storage.domain.PickingReturnsDetail;
import com.pureut.storage.dto.PickingReturnsDetailDto;
import com.pureut.storage.dto.PickingReturnsDetailListDto;
import com.pureut.storage.mapper.PickingRestDetailMapper;
import com.pureut.storage.mapper.PickingReturnsDetailMapper;
import com.pureut.storage.mapper.PickingReturnsMapper;
import com.pureut.storage.service.PickingRestDetailService;
import com.pureut.storage.service.PickingReturnsDetailService;
import com.pureut.storage.service.PickingReturnsService;
import com.pureut.system.api.domain.SysDictData;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author: YSL
 * @Date: 2023/2/3 17:53
 * @Desc: 委外退货明细
 */
@Service
public class PickingReturnsDetailServiceImpl extends ServiceImpl<PickingReturnsDetailMapper, PickingReturnsDetail> implements PickingReturnsDetailService {

    /**
     * 委外退货明细mapper
     */
    @Resource
    PickingReturnsDetailMapper pickingReturnsDetailMapper;

    /**
     * 查询委外退货明细列表
     * @param docNum
     * @return
     */
    @Override
    public List<PickingReturnsDetailListDto> getReturnsList(String docNum) {

        // 委外退货明细物料状态
        List<SysDictData> statusArray = DictUtils.getDictCache("picking_returns_detail");
        Map<String, String> materialMap = statusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 网型
        List<SysDictData> meshTypeArray = DictUtils.getDictCache("sys_of_type");
        Map<String, String> meshTypeMap = meshTypeArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 铺网类型
        List<SysDictData> layingTypeArray = DictUtils.getDictCache("sys_type_net");
        Map<String, String> layingTypeMap = layingTypeArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));


        List<PickingReturnsDetailListDto> returnsList = pickingReturnsDetailMapper.getReturnsList(docNum);
        for (PickingReturnsDetailListDto pickingReturnsDetailListDto : returnsList){
            // 物料状态
            pickingReturnsDetailListDto.setWodStatusDict(materialMap.get(String.valueOf(pickingReturnsDetailListDto.getWodStatus())));

            // 网型状态
            pickingReturnsDetailListDto.setMeshTypeDict(meshTypeMap.get(String.valueOf(pickingReturnsDetailListDto.getMeshType())));

            // 铺网类型状态
            pickingReturnsDetailListDto.setTypeOfLayingDict(layingTypeMap.get(String.valueOf(pickingReturnsDetailListDto.getTypeOfLaying())));
        }

        return returnsList;
    }
}
